//
//  CoursesClassTableViewCell.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/20.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "CoursesClassTableViewCell.h"

@implementation CoursesClassTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.layer.cornerRadius = 2;
        self.layer.masksToBounds = YES;
        
        /**
         课程图片
         */
        UIImageView *courseImageView = [[UIImageView alloc] init];
        courseImageView.contentMode = UIViewContentModeScaleAspectFill;
        courseImageView.layer.masksToBounds = YES;
//        courseImageView.backgroundColor = CSRedColor;
        [self.contentView addSubview:courseImageView];
        self.courseImageView = courseImageView;
        
        /**
         课程名字
         */
        UILabel *courseLabel = [[UILabel alloc] init];
        courseLabel.text = @"主题健身";
        courseLabel.font = TitleBoldFont;
        courseLabel.textColor = CSColorFromRGB(0x212121);
        [self.contentView addSubview:courseLabel];
        self.courseLabel = courseLabel;
        
        /**
         课程时间
         */
        UILabel *courseTimeLabel = [[UILabel alloc] init];
        courseTimeLabel.text = @"26min";
        courseTimeLabel.textColor = CSColorFromRGB(0x666666);
        courseTimeLabel.font = MidBigFont;
        [self.contentView addSubview:courseTimeLabel];
        self.courseTimeLabel = courseTimeLabel;
        
        /**
         类型背景
         */
        UIImageView *typeImageView = [[UIImageView alloc] init];
        typeImageView.image = [UIImage imageNamed:@"courseshare_label_course"];
        [self.contentView addSubview:typeImageView];
        self.typeImageView = typeImageView;
        
        /**
         类型图片
         */
        UILabel *typeLabel = [[UILabel alloc] init];
        typeLabel.text = @"团体课";
        typeLabel.font = MidFont;
        typeLabel.textColor = TFColor;
        [self.contentView addSubview:typeLabel];
        self.typeLabel = typeLabel;
        
        
        UIButton *selectBtn = [[UIButton alloc] init];
        selectBtn.userInteractionEnabled = NO;
        [selectBtn setImage:@"choose-no"];
        [selectBtn setSelectedImage:@"choose-yes"];
        selectBtn.hidden = YES;
        [self.contentView addSubview:selectBtn];
        self.selectBtn = selectBtn;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     课程图片
     */
    [self.courseImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.width.mas_equalTo(self.contentView);
        
        make.height.mas_equalTo(200);
    }];

    /**
     课程名字
     */
    [self.courseLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.courseImageView.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.contentView).offset(-20);
        
        make.left.mas_equalTo(self.contentView).offset(12);
    }];
    
    
    /**
     课程时间
     */
    [self.courseTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.contentView).offset(-12);
        
        make.centerY.mas_equalTo(self.courseLabel);
    }];
    
    /**
     类型背景
     */
    [self.typeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.contentView);
        
        make.top.mas_equalTo(self.contentView).offset(15);
        
        make.width.mas_equalTo(65);
    }];
    
    [self.typeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.typeImageView);
        
        make.left.mas_equalTo(self.typeImageView).offset(10);
    }];
    
    [self.selectBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView);
        
        make.right.mas_equalTo(self.contentView).offset(-15);
    }];
}

-(void)setSelectBtnSelect:(BOOL)selectBtnSelect{
    
    self.selectBtn.selected = selectBtnSelect;
}


-(void)setCourseModel:(CourseModel *)courseModel{
    
    _courseModel = courseModel;
    
    [self.courseImageView sd_setImageWithURL:[NSURL URLWithString:courseModel.Pic] placeholderImage:PlaceHold];
    
    self.courseLabel.text = courseModel.Name;
    
    self.courseTimeLabel.text = [NSString stringWithFormat:@"%@min",courseModel.Times];
    
    if ([courseModel.TypeID isEqualToString:@"团课"]) {
        
        self.typeLabel.text = @"团体课";
    }
    else{
        
        self.typeLabel.text = @"私教课";
    }
}

@end
